package com.bdzl.credit.service.impl;

import com.bdzl.credit.service.CreditService;
import com.bdzl.credit.dao.CreditDao;
import com.bdzl.credit.service.UserBlackService;
import com.bdzl.credit.servicefeign.FeignAdminService;
import com.bdzl.pub.entity.data.UserInfoDO;
import com.bdzl.pub.entity.loan.CreditDO;
import com.bdzl.pub.entity.loan.UserBlackDO;
import com.bdzl.pub.vo.data.UserInfoVO;
import com.bdzl.pub.vo.loan.CreditVO;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class CreditServiceImpl implements CreditService {
	@Autowired
	private CreditDao creditDao;
	@Autowired
	private UserBlackService userBlackService;
	@Autowired
	private FeignAdminService feignAdminService;

	@Override
	public CreditDO get(Integer creditId){
		return creditDao.get(creditId);
	}
	@Override
	public List<CreditDO> list(Map<String, Object> map){
		return creditDao.list(map);
	}

	@Override
	public List<CreditVO> CreditVOlist(Map<String, Object> map){
		List<CreditVO> list = creditDao.CreditVOlist(map);
		for (CreditVO item:list) {
			UserInfoDO oneUserInfo = feignAdminService.getSpouse(item.getCreditCardid());
			if (oneUserInfo!=null){
				item.setUserInfoVO(oneUserInfo);
			}
		}
		return list;
	}

	@Override
	public int count(Map<String, Object> map){
		return creditDao.count(map);
	}

	@Override
	public int save(CreditDO credit){
		return creditDao.save(credit);
	}

	@Override
	public int update(CreditDO credit){
		return creditDao.update(credit);
	}

	@Override
	public int remove(Integer creditId){
		return creditDao.remove(creditId);
	}

	@Override
	public int batchRemove(Integer[] creditIds){
		return creditDao.batchRemove(creditIds);
	}

	/**
	 * @Description: TODO 根据身份证号查询征信数据 以及黑白名单状态
	 * @param cardId 身份证号
	 * @return: com.bdzl.pub.entity.loan.CreditDO
	 * @Author: Ming
	 * @Date: 2021/5/18 10:31
	 */
	@Override
	public CreditVO getCreditByCardId(String cardId) {
		CreditVO creditVO = new CreditVO();
		UserBlackDO byBlackCardid = userBlackService.getByBlackCardid(cardId);
		if (byBlackCardid==null){
			creditVO = creditDao.getCreditByCardId(cardId);
			return creditVO;
		}else {
			creditVO = creditDao.getCreditByCardId(cardId);
		}
		if (creditVO!=null) {
			creditVO.setCreditType(byBlackCardid.getBlackType());
		}else {
			creditVO = new CreditVO();
			creditVO.setCreditType(byBlackCardid.getBlackType());
		}
		return creditVO;
	}

}
